{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "from sklearn.preprocessing import OneHotEncoder,Binarizer\n",
    "from sklearn.model_selection import train_test_split\n",
    "import numpy as np\n",
    "from sklearn.linear_model import LogisticRegression,LinearRegression\n",
    "from sklearn.ensemble import RandomForestClassifier\n",
    "from sklearn.tree import DecisionTreeClassifier\n",
    "from sklearn.metrics import accuracy_score,confusion_matrix,mean_squared_error,recall_score,roc_auc_score,precision_score,f1_score\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "import joblib\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.metrics import classification_report\n",
    "from sklearn.metrics import RocCurveDisplay\n",
    "from sklearn import metrics\n",
    "from sklearn.metrics import precision_recall_curve\n",
    "from sklearn.feature_extraction.text import CountVectorizer,TfidfVectorizer\n",
    "import jieba\n",
    "from sklearn.cluster import KMeans\n",
    "from sklearn.impute import SimpleImputer\n",
    "from xgboost import XGBRegressor\n",
    "from sklearn.ensemble import GradientBoostingRegressor\n",
    "from sklearn.metrics import r2_score, mean_absolute_error"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "data": {
      "text/plain": "       月收入  年龄  性别  历史授信额度  历史违约次数  信用评分\n0     7783  29   0   32274       3    73\n1     7836  40   1    6681       4    72\n2     6398  25   0   26038       2    74\n3     6483  23   1   24584       4    65\n4     5167  23   1    6710       3    73\n..     ...  ..  ..     ...     ...   ...\n995  12873  52   1   58190       2    87\n996  11478  36   0   95688       1    81\n997  14105  45   1   76221       2    89\n998  11914  37   1   39906       2    83\n999  14467  45   0   84052       2    83\n\n[1000 rows x 6 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>月收入</th>\n      <th>年龄</th>\n      <th>性别</th>\n      <th>历史授信额度</th>\n      <th>历史违约次数</th>\n      <th>信用评分</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>7783</td>\n      <td>29</td>\n      <td>0</td>\n      <td>32274</td>\n      <td>3</td>\n      <td>73</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>7836</td>\n      <td>40</td>\n      <td>1</td>\n      <td>6681</td>\n      <td>4</td>\n      <td>72</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>6398</td>\n      <td>25</td>\n      <td>0</td>\n      <td>26038</td>\n      <td>2</td>\n      <td>74</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>6483</td>\n      <td>23</td>\n      <td>1</td>\n      <td>24584</td>\n      <td>4</td>\n      <td>65</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>5167</td>\n      <td>23</td>\n      <td>1</td>\n      <td>6710</td>\n      <td>3</td>\n      <td>73</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>995</th>\n      <td>12873</td>\n      <td>52</td>\n      <td>1</td>\n      <td>58190</td>\n      <td>2</td>\n      <td>87</td>\n    </tr>\n    <tr>\n      <th>996</th>\n      <td>11478</td>\n      <td>36</td>\n      <td>0</td>\n      <td>95688</td>\n      <td>1</td>\n      <td>81</td>\n    </tr>\n    <tr>\n      <th>997</th>\n      <td>14105</td>\n      <td>45</td>\n      <td>1</td>\n      <td>76221</td>\n      <td>2</td>\n      <td>89</td>\n    </tr>\n    <tr>\n      <th>998</th>\n      <td>11914</td>\n      <td>37</td>\n      <td>1</td>\n      <td>39906</td>\n      <td>2</td>\n      <td>83</td>\n    </tr>\n    <tr>\n      <th>999</th>\n      <td>14467</td>\n      <td>45</td>\n      <td>0</td>\n      <td>84052</td>\n      <td>2</td>\n      <td>83</td>\n    </tr>\n  </tbody>\n</table>\n<p>1000 rows × 6 columns</p>\n</div>"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_excel(\"C:\\\\Users\\\\Administrator\\\\Desktop\\\\月考练习算法题 (2)\\\\月考练习算法题\\\\第6套（修改2）\\\\专高6月考-06附件\\\\信用评分卡模型.xlsx\")\n",
    "df"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "    月收入  年龄  性别  历史授信额度  历史违约次数  信用评分\n0  7783  29   0   32274       3    73\n1  7836  40   1    6681       4    72\n2  6398  25   0   26038       2    74\n3  6483  23   1   24584       4    65\n4  5167  23   1    6710       3    73",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>月收入</th>\n      <th>年龄</th>\n      <th>性别</th>\n      <th>历史授信额度</th>\n      <th>历史违约次数</th>\n      <th>信用评分</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>7783</td>\n      <td>29</td>\n      <td>0</td>\n      <td>32274</td>\n      <td>3</td>\n      <td>73</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>7836</td>\n      <td>40</td>\n      <td>1</td>\n      <td>6681</td>\n      <td>4</td>\n      <td>72</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>6398</td>\n      <td>25</td>\n      <td>0</td>\n      <td>26038</td>\n      <td>2</td>\n      <td>74</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>6483</td>\n      <td>23</td>\n      <td>1</td>\n      <td>24584</td>\n      <td>4</td>\n      <td>65</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>5167</td>\n      <td>23</td>\n      <td>1</td>\n      <td>6710</td>\n      <td>3</td>\n      <td>73</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1000 entries, 0 to 999\n",
      "Data columns (total 6 columns):\n",
      " #   Column  Non-Null Count  Dtype\n",
      "---  ------  --------------  -----\n",
      " 0   月收入     1000 non-null   int64\n",
      " 1   年龄      1000 non-null   int64\n",
      " 2   性别      1000 non-null   int64\n",
      " 3   历史授信额度  1000 non-null   int64\n",
      " 4   历史违约次数  1000 non-null   int64\n",
      " 5   信用评分    1000 non-null   int64\n",
      "dtypes: int64(6)\n",
      "memory usage: 47.0 KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "data": {
      "text/plain": "                月收入           年龄           性别        历史授信额度       历史违约次数  \\\ncount   1000.000000  1000.000000  1000.000000   1000.000000  1000.000000   \nmean   10182.061000    39.075000     0.507000  48783.005000     2.012000   \nstd     2719.251125     9.610085     0.500201  27133.636467     1.554436   \nmin     5007.000000    20.000000     0.000000   5073.000000     0.000000   \n25%     8160.250000    32.000000     0.000000  26907.750000     1.000000   \n50%    10038.000000    39.000000     1.000000  42948.000000     2.000000   \n75%    12498.250000    47.000000     1.000000  72386.500000     3.000000   \nmax    14999.000000    55.000000     1.000000  99991.000000     5.000000   \n\n              信用评分  \ncount  1000.000000  \nmean     79.558000  \nstd       7.749754  \nmin      60.000000  \n25%      74.000000  \n50%      81.000000  \n75%      86.000000  \nmax      90.000000  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>月收入</th>\n      <th>年龄</th>\n      <th>性别</th>\n      <th>历史授信额度</th>\n      <th>历史违约次数</th>\n      <th>信用评分</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>count</th>\n      <td>1000.000000</td>\n      <td>1000.000000</td>\n      <td>1000.000000</td>\n      <td>1000.000000</td>\n      <td>1000.000000</td>\n      <td>1000.000000</td>\n    </tr>\n    <tr>\n      <th>mean</th>\n      <td>10182.061000</td>\n      <td>39.075000</td>\n      <td>0.507000</td>\n      <td>48783.005000</td>\n      <td>2.012000</td>\n      <td>79.558000</td>\n    </tr>\n    <tr>\n      <th>std</th>\n      <td>2719.251125</td>\n      <td>9.610085</td>\n      <td>0.500201</td>\n      <td>27133.636467</td>\n      <td>1.554436</td>\n      <td>7.749754</td>\n    </tr>\n    <tr>\n      <th>min</th>\n      <td>5007.000000</td>\n      <td>20.000000</td>\n      <td>0.000000</td>\n      <td>5073.000000</td>\n      <td>0.000000</td>\n      <td>60.000000</td>\n    </tr>\n    <tr>\n      <th>25%</th>\n      <td>8160.250000</td>\n      <td>32.000000</td>\n      <td>0.000000</td>\n      <td>26907.750000</td>\n      <td>1.000000</td>\n      <td>74.000000</td>\n    </tr>\n    <tr>\n      <th>50%</th>\n      <td>10038.000000</td>\n      <td>39.000000</td>\n      <td>1.000000</td>\n      <td>42948.000000</td>\n      <td>2.000000</td>\n      <td>81.000000</td>\n    </tr>\n    <tr>\n      <th>75%</th>\n      <td>12498.250000</td>\n      <td>47.000000</td>\n      <td>1.000000</td>\n      <td>72386.500000</td>\n      <td>3.000000</td>\n      <td>86.000000</td>\n    </tr>\n    <tr>\n      <th>max</th>\n      <td>14999.000000</td>\n      <td>55.000000</td>\n      <td>1.000000</td>\n      <td>99991.000000</td>\n      <td>5.000000</td>\n      <td>90.000000</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe()\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "data": {
      "text/plain": "(1000, 6)"
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "月收入       0\n年龄        0\n性别        0\n历史授信额度    0\n历史违约次数    0\n信用评分      0\ndtype: int64"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.isnull().sum()\n",
    "df.fillna(df.mean(), inplace=True)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "data": {
      "text/plain": "       月收入  年龄  性别  历史授信额度  历史违约次数  信用评分\n0     7783  29   0   32274       3    73\n1     7836  40   1    6681       4    72\n2     6398  25   0   26038       2    74\n3     6483  23   1   24584       4    65\n4     5167  23   1    6710       3    73\n..     ...  ..  ..     ...     ...   ...\n995  12873  52   1   58190       2    87\n996  11478  36   0   95688       1    81\n997  14105  45   1   76221       2    89\n998  11914  37   1   39906       2    83\n999  14467  45   0   84052       2    83\n\n[1000 rows x 6 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>月收入</th>\n      <th>年龄</th>\n      <th>性别</th>\n      <th>历史授信额度</th>\n      <th>历史违约次数</th>\n      <th>信用评分</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>7783</td>\n      <td>29</td>\n      <td>0</td>\n      <td>32274</td>\n      <td>3</td>\n      <td>73</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>7836</td>\n      <td>40</td>\n      <td>1</td>\n      <td>6681</td>\n      <td>4</td>\n      <td>72</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>6398</td>\n      <td>25</td>\n      <td>0</td>\n      <td>26038</td>\n      <td>2</td>\n      <td>74</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>6483</td>\n      <td>23</td>\n      <td>1</td>\n      <td>24584</td>\n      <td>4</td>\n      <td>65</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>5167</td>\n      <td>23</td>\n      <td>1</td>\n      <td>6710</td>\n      <td>3</td>\n      <td>73</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>995</th>\n      <td>12873</td>\n      <td>52</td>\n      <td>1</td>\n      <td>58190</td>\n      <td>2</td>\n      <td>87</td>\n    </tr>\n    <tr>\n      <th>996</th>\n      <td>11478</td>\n      <td>36</td>\n      <td>0</td>\n      <td>95688</td>\n      <td>1</td>\n      <td>81</td>\n    </tr>\n    <tr>\n      <th>997</th>\n      <td>14105</td>\n      <td>45</td>\n      <td>1</td>\n      <td>76221</td>\n      <td>2</td>\n      <td>89</td>\n    </tr>\n    <tr>\n      <th>998</th>\n      <td>11914</td>\n      <td>37</td>\n      <td>1</td>\n      <td>39906</td>\n      <td>2</td>\n      <td>83</td>\n    </tr>\n    <tr>\n      <th>999</th>\n      <td>14467</td>\n      <td>45</td>\n      <td>0</td>\n      <td>84052</td>\n      <td>2</td>\n      <td>83</td>\n    </tr>\n  </tbody>\n</table>\n<p>1000 rows × 6 columns</p>\n</div>"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.drop_duplicates(inplace=True)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [],
   "source": [
    "# 4、自主选择合适的方法进行特征选择(3分)\n",
    "X = df.drop('信用评分',axis=1)\n",
    "y = df['信用评分']\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "       月收入  年龄  性别  历史授信额度  历史违约次数\n29    7891  40   0    5955       5\n535  13067  43   1   49910       0\n695  11672  46   1   55170       0\n557  12391  43   1   73136       2\n836  13277  46   0   48947       0\n..     ...  ..  ..     ...     ...\n106   6206  22   0   16004       2\n270   9756  40   1   10802       2\n860  10066  48   0   55753       1\n435  13939  42   0   91627       1\n102   9758  28   0    6198       2\n\n[800 rows x 5 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>月收入</th>\n      <th>年龄</th>\n      <th>性别</th>\n      <th>历史授信额度</th>\n      <th>历史违约次数</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>29</th>\n      <td>7891</td>\n      <td>40</td>\n      <td>0</td>\n      <td>5955</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>535</th>\n      <td>13067</td>\n      <td>43</td>\n      <td>1</td>\n      <td>49910</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>695</th>\n      <td>11672</td>\n      <td>46</td>\n      <td>1</td>\n      <td>55170</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>557</th>\n      <td>12391</td>\n      <td>43</td>\n      <td>1</td>\n      <td>73136</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>836</th>\n      <td>13277</td>\n      <td>46</td>\n      <td>0</td>\n      <td>48947</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>106</th>\n      <td>6206</td>\n      <td>22</td>\n      <td>0</td>\n      <td>16004</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>270</th>\n      <td>9756</td>\n      <td>40</td>\n      <td>1</td>\n      <td>10802</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>860</th>\n      <td>10066</td>\n      <td>48</td>\n      <td>0</td>\n      <td>55753</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>435</th>\n      <td>13939</td>\n      <td>42</td>\n      <td>0</td>\n      <td>91627</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>102</th>\n      <td>9758</td>\n      <td>28</td>\n      <td>0</td>\n      <td>6198</td>\n      <td>2</td>\n    </tr>\n  </tbody>\n</table>\n<p>800 rows × 5 columns</p>\n</div>"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "F:\\python38\\lib\\site-packages\\sklearn\\base.py:458: UserWarning: X has feature names, but StandardScaler was fitted without feature names\n",
      "  warnings.warn(\n"
     ]
    }
   ],
   "source": [
    "s = StandardScaler()\n",
    "X_train = s.fit_transform(X_train)\n",
    "X_test = s.transform(X_test)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "outputs": [
    {
     "data": {
      "text/plain": "XGBRegressor(base_score=None, booster=None, callbacks=None,\n             colsample_bylevel=None, colsample_bynode=None,\n             colsample_bytree=None, device=None, early_stopping_rounds=None,\n             enable_categorical=False, eval_metric=None, feature_types=None,\n             gamma=None, grow_policy=None, importance_type=None,\n             interaction_constraints=None, learning_rate=None, max_bin=None,\n             max_cat_threshold=None, max_cat_to_onehot=None,\n             max_delta_step=None, max_depth=None, max_leaves=None,\n             min_child_weight=None, missing=nan, monotone_constraints=None,\n             multi_strategy=None, n_estimators=None, n_jobs=None,\n             num_parallel_tree=None, random_state=None, ...)",
      "text/html": "<style>#sk-container-id-1 {color: black;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>XGBRegressor(base_score=None, booster=None, callbacks=None,\n             colsample_bylevel=None, colsample_bynode=None,\n             colsample_bytree=None, device=None, early_stopping_rounds=None,\n             enable_categorical=False, eval_metric=None, feature_types=None,\n             gamma=None, grow_policy=None, importance_type=None,\n             interaction_constraints=None, learning_rate=None, max_bin=None,\n             max_cat_threshold=None, max_cat_to_onehot=None,\n             max_delta_step=None, max_depth=None, max_leaves=None,\n             min_child_weight=None, missing=nan, monotone_constraints=None,\n             multi_strategy=None, n_estimators=None, n_jobs=None,\n             num_parallel_tree=None, random_state=None, ...)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">XGBRegressor</label><div class=\"sk-toggleable__content\"><pre>XGBRegressor(base_score=None, booster=None, callbacks=None,\n             colsample_bylevel=None, colsample_bynode=None,\n             colsample_bytree=None, device=None, early_stopping_rounds=None,\n             enable_categorical=False, eval_metric=None, feature_types=None,\n             gamma=None, grow_policy=None, importance_type=None,\n             interaction_constraints=None, learning_rate=None, max_bin=None,\n             max_cat_threshold=None, max_cat_to_onehot=None,\n             max_delta_step=None, max_depth=None, max_leaves=None,\n             min_child_weight=None, missing=nan, monotone_constraints=None,\n             multi_strategy=None, n_estimators=None, n_jobs=None,\n             num_parallel_tree=None, random_state=None, ...)</pre></div></div></div></div></div>"
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xgb = XGBRegressor()\n",
    "xgb.fit(X_train,y_train)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "outputs": [
    {
     "data": {
      "text/plain": "GradientBoostingRegressor()",
      "text/html": "<style>#sk-container-id-2 {color: black;}#sk-container-id-2 pre{padding: 0;}#sk-container-id-2 div.sk-toggleable {background-color: white;}#sk-container-id-2 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-2 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-2 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-2 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-2 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-2 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-2 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-2 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-2 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-2 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-2 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-2 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-2 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-2 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-2 div.sk-item {position: relative;z-index: 1;}#sk-container-id-2 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-2 div.sk-item::before, #sk-container-id-2 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-2 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-2 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-2 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-2 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-2 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-2 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-2 div.sk-label-container {text-align: center;}#sk-container-id-2 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-2 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-2\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>GradientBoostingRegressor()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-2\" type=\"checkbox\" checked><label for=\"sk-estimator-id-2\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">GradientBoostingRegressor</label><div class=\"sk-toggleable__content\"><pre>GradientBoostingRegressor()</pre></div></div></div></div></div>"
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gbdt = GradientBoostingRegressor()\n",
    "gbdt.fit(X_train,y_train)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "outputs": [],
   "source": [
    "xgb_parameters = {\"max_depth\":[1,3,5],\"learning_rate\":[0.1,0.2,0.3]}\n",
    "gbdt_parameters = {\"learning_rate\":[0.1,0.2,0.3],\n",
    "              \"max_depth\":[1,3,5]}\n",
    "clf_tree = GridSearchCV(xgb, xgb_parameters,cv=5)\n",
    "clf_sl = GridSearchCV(gbdt, gbdt_parameters,cv=5)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "outputs": [
    {
     "data": {
      "text/plain": "{'learning_rate': 0.1, 'max_depth': 3}"
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_tree.fit(X_train,y_train)\n",
    "clf_tree.best_params_"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "outputs": [
    {
     "data": {
      "text/plain": "{'learning_rate': 0.1, 'max_depth': 3}"
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_sl.fit(X_train,y_train)\n",
    "clf_sl.best_params_"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "outputs": [
    {
     "data": {
      "text/plain": "array([80.4777  , 83.8484  , 80.4777  , 83.8484  , 78.744965, 80.371574,\n       78.744965, 80.4777  , 80.4777  , 78.744965, 80.4777  , 78.744965,\n       78.85109 , 83.8484  , 80.371574, 80.371574, 78.744965, 78.744965,\n       83.8484  , 78.744965, 78.85109 , 78.85109 , 78.85109 , 78.744965,\n       78.85109 , 78.744965, 78.744965, 78.85109 , 83.8484  , 83.8484  ,\n       78.744965, 78.744965, 80.4777  , 78.85109 , 78.744965, 78.744965,\n       78.85109 , 80.371574, 83.8484  , 78.744965, 78.744965, 78.85109 ,\n       78.85109 , 83.95452 , 78.85109 , 78.85109 , 78.744965, 78.744965,\n       78.744965, 80.371574, 78.85109 , 78.744965, 78.744965, 80.371574,\n       78.744965, 78.85109 , 80.371574, 78.744965, 78.85109 , 78.744965,\n       78.85109 , 78.744965, 78.744965, 78.744965, 78.744965, 78.85109 ,\n       78.85109 , 78.85109 , 78.744965, 83.8484  , 78.744965, 83.8484  ,\n       78.744965, 83.95452 , 78.85109 , 78.85109 , 80.371574, 78.85109 ,\n       78.85109 , 78.744965, 83.8484  , 78.85109 , 78.744965, 78.744965,\n       78.85109 , 83.95452 , 78.744965, 80.371574, 80.4777  , 78.85109 ,\n       78.85109 , 80.371574, 83.95452 , 78.744965, 83.95452 , 83.8484  ,\n       83.8484  , 78.85109 , 78.744965, 80.4777  , 80.4777  , 78.744965,\n       80.371574, 78.744965, 80.4777  , 83.95452 , 83.8484  , 83.8484  ,\n       78.85109 , 80.371574, 78.744965, 78.85109 , 80.4777  , 80.371574,\n       78.85109 , 83.8484  , 78.744965, 83.8484  , 80.371574, 78.85109 ,\n       83.95452 , 83.95452 , 80.4777  , 78.744965, 78.85109 , 80.371574,\n       83.95452 , 78.85109 , 80.371574, 83.8484  , 80.4777  , 80.371574,\n       78.85109 , 78.744965, 83.95452 , 78.744965, 78.85109 , 78.744965,\n       78.85109 , 78.85109 , 78.85109 , 78.85109 , 83.95452 , 78.744965,\n       80.4777  , 80.4777  , 80.4777  , 78.85109 , 78.85109 , 78.744965,\n       80.4777  , 78.744965, 83.8484  , 78.85109 , 80.371574, 78.85109 ,\n       78.744965, 83.95452 , 78.85109 , 78.85109 , 83.95452 , 78.85109 ,\n       78.744965, 83.95452 , 80.4777  , 80.371574, 78.744965, 80.4777  ,\n       78.744965, 78.744965, 78.85109 , 83.95452 , 78.744965, 80.4777  ,\n       78.744965, 78.85109 , 78.744965, 78.744965, 83.8484  , 78.85109 ,\n       80.371574, 80.4777  , 78.744965, 78.744965, 80.371574, 78.85109 ,\n       78.744965, 78.744965, 78.744965, 80.371574, 80.4777  , 80.371574,\n       80.4777  , 78.744965, 78.744965, 78.85109 , 78.85109 , 78.85109 ,\n       78.744965, 78.85109 ], dtype=float32)"
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xgb_best = clf_tree.best_estimator_.predict(X_test)\n",
    "xgb_best"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "outputs": [
    {
     "data": {
      "text/plain": "array([74.58473939, 80.22729768, 74.58473939, 80.22729768, 75.30875432,\n       74.58473939, 75.30875432, 74.58473939, 74.58473939, 75.30875432,\n       74.58473939, 75.30875432, 75.30875432, 80.22729768, 74.58473939,\n       74.58473939, 75.30875432, 75.30875432, 80.22729768, 75.30875432,\n       75.30875432, 75.30875432, 75.30875432, 75.30875432, 75.30875432,\n       75.30875432, 75.30875432, 75.30875432, 80.22729768, 80.22729768,\n       75.30875432, 75.30875432, 74.58473939, 75.30875432, 75.30875432,\n       75.30875432, 75.30875432, 74.58473939, 80.22729768, 75.30875432,\n       75.30875432, 75.30875432, 75.30875432, 80.22729768, 75.30875432,\n       75.30875432, 75.30875432, 75.30875432, 75.30875432, 74.58473939,\n       75.30875432, 75.30875432, 75.30875432, 74.58473939, 75.30875432,\n       75.30875432, 74.58473939, 75.30875432, 75.30875432, 75.30875432,\n       75.30875432, 75.30875432, 75.30875432, 75.30875432, 75.30875432,\n       75.30875432, 75.30875432, 75.30875432, 75.30875432, 80.22729768,\n       75.30875432, 80.22729768, 75.30875432, 80.22729768, 75.30875432,\n       75.30875432, 74.58473939, 75.30875432, 75.30875432, 75.30875432,\n       80.22729768, 75.30875432, 75.30875432, 75.30875432, 75.30875432,\n       80.22729768, 75.30875432, 74.58473939, 74.58473939, 75.30875432,\n       75.30875432, 74.58473939, 80.22729768, 75.30875432, 80.22729768,\n       80.22729768, 80.22729768, 75.30875432, 75.30875432, 74.58473939,\n       74.58473939, 75.30875432, 74.58473939, 75.30875432, 74.58473939,\n       80.22729768, 80.22729768, 80.22729768, 75.30875432, 74.58473939,\n       75.30875432, 75.30875432, 74.58473939, 74.58473939, 75.30875432,\n       80.22729768, 75.30875432, 80.22729768, 74.58473939, 75.30875432,\n       80.22729768, 80.22729768, 74.58473939, 75.30875432, 75.30875432,\n       74.58473939, 80.22729768, 75.30875432, 74.58473939, 80.22729768,\n       74.58473939, 74.58473939, 75.30875432, 75.30875432, 80.22729768,\n       75.30875432, 75.30875432, 75.30875432, 75.30875432, 75.30875432,\n       75.30875432, 75.30875432, 80.22729768, 75.30875432, 74.58473939,\n       74.58473939, 74.58473939, 75.30875432, 75.30875432, 75.30875432,\n       74.58473939, 75.30875432, 80.22729768, 75.30875432, 74.58473939,\n       75.30875432, 75.30875432, 80.22729768, 75.30875432, 75.30875432,\n       80.22729768, 75.30875432, 75.30875432, 80.22729768, 74.58473939,\n       74.58473939, 75.30875432, 74.58473939, 75.30875432, 75.30875432,\n       75.30875432, 80.22729768, 75.30875432, 74.58473939, 75.30875432,\n       75.30875432, 75.30875432, 75.30875432, 80.22729768, 75.30875432,\n       74.58473939, 74.58473939, 75.30875432, 75.30875432, 74.58473939,\n       75.30875432, 75.30875432, 75.30875432, 75.30875432, 74.58473939,\n       74.58473939, 74.58473939, 74.58473939, 75.30875432, 75.30875432,\n       75.30875432, 75.30875432, 75.30875432, 75.30875432, 75.30875432])"
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gbdt_best = clf_sl.best_estimator_.predict(X_test)\n",
    "gbdt_best\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "outputs": [
    {
     "data": {
      "text/plain": "58.35205256158137"
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mean_squared_error(y_test,xgb_best)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "outputs": [
    {
     "data": {
      "text/plain": "73.39660709191645"
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mean_squared_error(y_test,gbdt_best)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "outputs": [
    {
     "data": {
      "text/plain": "-0.06762583500369401"
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r2_score(y_test,xgb_best)\n",
    "r2_score(y_test,gbdt_best)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "mean_absolute_error(y_test,xgb_best)\n",
    "mean_absolute_error(y_test,gbdt_best)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "outputs": [
    {
     "data": {
      "text/plain": "8.567181980786707"
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import math\n",
    "math.sqrt(mean_squared_error(y_test,xgb_best))\n",
    "math.sqrt(mean_squared_error(y_test,gbdt_best))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "outputs": [
    {
     "data": {
      "text/plain": "array([0.18659681, 0.19587171, 0.01596795, 0.29406998, 0.3074936 ],\n      dtype=float32)"
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_sl.best_estimator_.feature_importances_\n",
    "clf_tree.best_estimator_.feature_importances_"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "outputs": [
    {
     "data": {
      "text/plain": "['1.pkl']"
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "joblib.dump(clf_sl.best_estimator_,\"1.pkl\")\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "outputs": [
    {
     "data": {
      "text/plain": "['2.pkl']"
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "joblib.dump(clf_tree.best_estimator_,\"2.pkl\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}